package thread;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadpoolDemo {
    public static void main(String[] args) {

        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 10; i++) {
            Runnable r = new Runnable() {
                @Override
                public void run() {

                    Thread t = Thread.currentThread();
                    System.out.println(t + "正在运行任务");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                    }
                    System.out.println(t + "运行结束");

                }


                };
            threadPool.execute(r);
            System.out.println("将一个任务放到了线程池");
        }
    }
}